<template>
  <div class="company-container">
    <div class="topcount">
      <p v-if="calcTotal.length > 0">
        <img
          v-for="(v, i) in calcTotal"
          :src="require('../../assets/img/' + v + '.png')"
          :key="i"
          alt="加载失败"
        />
      </p>
      <p v-else>
        <img :src="require('../../assets/img/0.png')" alt="加载失败" />
      </p>
      <p class="totalCount">企业总数</p>
    </div>
    <div class="middlecount">
      <div class="sortcount left">
        <div class="dot normal"></div>
        <div class="auto">
          <p class="num">{{ companyData.normalCompanyNum | splitNumber }}</p>
          <p class="desc">无异常企业数</p>
        </div>
      </div>
      <div class="sortcount center">
        <div class="dot light"></div>
        <div class="auto">
          <p class="num">{{ companyData.mildCompanyNum | splitNumber }}</p>
          <p class="desc">轻度关注企业数</p>
        </div>
      </div>
      <div class="sortcount right">
        <div class="dot serious"></div>
        <div class="auto">
          <p class="num">{{ companyData.severeCompanyNum | splitNumber }}</p>
          <p class="desc">重点监管企业数</p>
        </div>
      </div>
    </div>
    <div class="bottomcount">
      <div
        class="line normal"
        :data-title="
          '无异常企业数' + '\n' + '：' + companyData.normalCompanyRate + '%'
        "
        :style="{ width: companyData.normalCompanyRate - 1 + '%' }"
      >
        <div class="explain">
          <p class="delt normaldelt"></p>
          <p class="scale">{{ companyData.normalCompanyRate }}</p>
        </div>
      </div>
      <div
        class="line light"
        :data-title="
          '轻度关注企业数' + '\n' + '：' + companyData.mildCompanyRate + '%'
        "
        :style="{ width: companyData.mildCompanyRate + '%' }"
      >
        <div class="explain top">
          <p class="scale">{{ companyData.mildCompanyRate }}</p>
          <p class="delt lightdelt"></p>
        </div>
      </div>
      <div
        class="line serious"
        :data-title="
          '重点监管企业数' + '\n' + '：' + companyData.severeCompanyRate + '%'
        "
        :style="{ width: companyData.severeCompanyRate + '%' }"
      >
        <div class="explain">
          <p class="delt seriousdelt"></p>
          <p class="scale">{{ companyData.severeCompanyRate }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'componyCount',
  data() {
    return {
      companyData: {},
    }
  },
  computed: {
    calcTotal() {
      return this.companyData.companyTotalNum
        ? (this.companyData.companyTotalNum + '').split('')
        : 0
    },
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData(type) {
      return this.axios({
        method: 'post',
        url: 'api-c/company/risk/stats/base/data',
      })
        .then((response) => {
          if (!response.data.hasError) {
            this.companyData = response.data.result
            this.draw()
          } else {
            this.$message.error(response.data.errorMsg)
          }
        })
        .catch((error) => {
          if (error.response) {
            this.$message.error(error.response.data)
          }
        })
    },
  },
}
</script>

<style lang="less" scoped>
@normal: #fbddd0;
@light: #f9a681;
@serious: #ed0c0c;
.company-container {
  width: 100%;
  height: 100%;
  .topcount {
    padding-top: 15px;
    text-align: center;
    img {
      width: 30px;
      height: 44px;
      margin-right: 6px;
    }
    .totalCount {
      font-size: 16px;
      font-family: Source Han Sans CN;
      font-weight: 500;
      color: #ffffff;
      margin-top: 15px;
    }
  }
  .middlecount {
    width: 100%;
    margin-top: 25px;
    font-size: 0;
    position: relative;
    .sortcount {
      display: inline-block;
      text-align: center;
      .auto {
        width: auto;
        .num {
          font-size: 24px;
          font-family: Source Han Sans CN;
          font-weight: 500;
          color: #fec03f;
          text-indent: 10px;
        }
        .desc {
          margin-top: 10px;
          text-align: left;
          padding-left: 14px;
          font-size: 12px;
          font-family: Source Han Sans CN;
          font-weight: 400;
          color: #ffffff;
        }
      }
      .dot {
        width: 8px;
        height: 8px;
        position: absolute;
        bottom: 3px;
        left: 0;
      }
    }
    .left {
      position: absolute;
      left: 0;
    }
    .center {
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
    }
    .right {
      position: absolute;
      right: 0;
    }
  }
  .bottomcount {
    width: 100%;
    font-size: 0;
    margin-top: 128px;
    .line {
      height: 8px;
      display: inline-block;
      position: relative;
      .explain {
        height: 30px;
        text-align: center;
        position: absolute;
        left: 50%;
        top: 8px;
        transform: translateX(-50%);
        .delt {
          display: inline-block;
          width: 0;
          height: 0px;
          border-bottom: 8px solid #fbddd0;
          border-left: 5px solid transparent;
          border-right: 5px solid transparent;
        }
        .normaldelt {
          border-bottom-color: @normal;
        }
        .lightdelt {
          border-bottom: 0;
          border-top: 8px solid @light;
        }
        .seriousdelt {
          border-bottom-color: @serious;
        }
        .scale {
          font-size: 12px;
          font-family: Source Han Sans CN;
          font-weight: 400;
          color: #ffffff;
          line-height: 16px;
        }
      }
      .top {
        top: auto;
        bottom: 4px;
      }
      &:hover {
        // background: rgb(72, 97, 116);
        cursor: pointer;
        &::before {
          display: block;
          width: 140px;
          position: absolute;
          top: -20px;
          right: 30%;
          z-index: 10;
          padding: 8px 8px;
          font-size: 12px;
          line-height: 14px;
          text-align: center;
          content: attr(data-title);
          //在这里设内置好title出现的位置就好了
          color: #ffffff;
          border-radius: 5px;
          background-color: rgba(47, 57, 65, 0.9);
        }
      }
    }
  }
}
.normal {
  background-color: @normal;
}
.light {
  background-color: @light;
}
.serious {
  background-color: @serious;
}
</style>
